import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUser = defineStore(
  'user',
  () => {
    const userInfo = ref({})
    const setUserInfo = (info) => {
      userInfo.value = info
    }

    const activeTab = ref('')
    const setActiveTab = (tab) => {
      activeTab.value = tab || 'index'
    }

    return {
      userInfo,
      setUserInfo,
      activeTab,
      setActiveTab,
    }
  },
  {
    persist: {
      storage: {
        getItem(key) {
          return uni.getStorageSync(key)
        },
        setItem(key, value) {
          uni.setStorageSync(key, value)
        },
      },
    },
  },
)
